package com.itheima.jingjie;

import java.util.*;

//this关键字问题(泛型类的构造方法)
/*定义泛型类并使用*/
public class 泛型类<T> {
    private T t;

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }

    public 泛型类(T t) {
        this.t = t;
    }

    public 泛型类() {
    }
}

class Test {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Object[] objects = list.toArray();
        System.out.println(Arrays.toString(objects));
        String[] strings = list.toArray(new String[list.size()]);
        System.out.println(list.toArray(new String[list.size()]));

        泛型类<String> fxl = new 泛型类<String>();
        fxl.setT("hello..............");
        String t = fxl.getT();
        System.out.println("输出:     ");
        System.out.println(t);
        System.out.println("..........................");
        泛型类<Integer> fx = new 泛型类<Integer>();
        fx.setT(22);
        Integer t1 = fx.getT();
        System.out.println(t1);
        System.out.println("多个类型的泛型类..........");
        FanXing<Integer, String> fan = new FanXing<Integer, String>(12, "222");
        String s = fan.toString();
        System.out.println(s);


    }
}

class FanXing<K, V> {
    K k;
    V v;

    public K getK() {
        return k;
    }

    public void setK(K k) {
        this.k = k;
    }

    public V getV() {
        return v;
    }

    public void setV(V v) {
        this.v = v;
    }

    public FanXing() {
    }

    public FanXing(K k, V v) {
        this.k = k;
        this.v = v;
    }

    @Override
    public String toString() {
        return "FanXing{" +
                "k=" + k +
                ", v=" + v +
                '}';
    }
}

class Test1 {
    public static void main(String[] args) {
        ArrayList<String> list = add(new ArrayList<String>(), "123", "abc");
        System.out.println(list);
        ArrayList<Integer> integers = add(new ArrayList<Integer>(), 12, 22);
        System.out.println(integers);

    }

    public static <T> ArrayList<T> add(ArrayList<T> list, T t1, T t2) {
        list.add(t1);
        list.add(t2);
        return list;
    }
}

class Test2 {
    public static void main(String[] args) {
        ArrayList<Integer> list1 = new ArrayList<>();
        ArrayList<String> list2 = new ArrayList<>();
        ArrayList<Number> list3 = new ArrayList<>();
        ArrayList<Object> list4 = new ArrayList<>();
        addextends(list1);
        //addextends(lis2);
        addextends(list3);
        //addextends(list4);
        //addsuper(list1);
        //addsuper(list2);
        addsuper(list3);
        addsuper(list4);

    }

    public static void addextends(ArrayList<? extends Number> list) {
        System.out.println(list);
    }

    public static void addsuper(ArrayList<? super Number> list) {
        System.out.println(list);
    }

}
class Test3{
    public static void main(String[] args) {
        Set<String> set=new TreeSet<>();
        set.add("123");
        set.add("234");
        set.add("345");
        set.add("456");
        set.add("567");
        set.add("678");
        for (String s : set) {
            System.out.println(s);
        }
        System.out.println(".....................");
        Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }

    }
}

//TreeSet集合
class TestTreeSet{
    public static void main(String[] args) {
//        ArrayList<Integer> list = new ArrayList<>();
//        Collections.addAll(list,52,42,32,22);
        TreeSet<Integer> set=new TreeSet<>();
        set.add(12);
        set.add(3);
        set.add(4);
        set.add(5);
        set.add(6);
        set.add(8);
        for (Integer integer : set) {
            System.out.println(integer);
        }

    }
}